package db_struct

import (
	"github.com/astaxie/beego/orm"
	"time"
)

func init() {
	orm.RegisterModel(
		new(Admin),
		new(AdminAccessToken),
		new(AdminDepartment),
		new(AdminGroup),
		new(AdminGroupPower),
		new(AdminInGroup),
		new(AdminPower),
		new(AdminSysFunc),
		new(AdminSysFuncGroup),
		new(Region),
	)
}

//运营管理人员
type Admin struct {
	Id       int
	Created  time.Time `orm:"auto_now_add;type(datetime)"`
	Updated  time.Time `orm:"auto_now;type(datetime)"`
	Account  string    `orm:"unique"`    //用户名
	Password string    `orm:"size(128)"` //密码
	Name     string    `orm:"size(64)"`  //姓名
	Mobile   string    `orm:"size(64)"`  //手机号
	Sex      int8      //性别
	Email    string    //邮箱
	Status   int8      //用户状态
}

//管理员Token表
type AdminAccessToken struct {
	Id         int
	Created    time.Time `orm:"auto_now_add;type(datetime)"`
	Updated    time.Time `orm:"auto_now;type(datetime)"`
	Aid        int
	Token      string `orm:"size(512)"`
	AuthTarget int8   //授权对象
	ExpiryTime int64  //过期时间
}

func (t *AdminAccessToken) TableUnique() [][]string {
	return [][]string{
		{"Aid", "AuthTarget"},
	}
}

//管理员部门
type AdminDepartment struct {
	Id       int
	Created  time.Time `orm:"auto_now_add;type(datetime)"`
	Updated  time.Time `orm:"auto_now;type(datetime)"`
	Pid      int       //父id
	Name     string    `orm:"size(100)"`        //名称
	Code     string    `orm:"size(100);unique"` //编码
	Status   int8      //状态
	Describe int8      //描述
	IsDel    int8      //删除标记
}

//管理员分组
type AdminGroup struct {
	Id       int
	Created  time.Time `orm:"auto_now_add;type(datetime)"`
	Updated  time.Time `orm:"auto_now;type(datetime)"`
	Name     string    `orm:"size(100);unique"` //分组名称
	IsSupper int8      //超级用户
	Remark   string    //备注
}

//管理员分组权限
type AdminGroupPower struct {
	Id    int
	GId   int //分组
	Aid   int //权限项
	Power int
}

func (t *AdminGroupPower) TableUnique() [][]string {
	return [][]string{
		{"GId", "Aid"},
	}
}

//管理系统功能
type AdminSysFunc struct {
	Id       int
	Created  time.Time `orm:"auto_now_add;type(datetime)"`
	Updated  time.Time `orm:"auto_now;type(datetime)"`
	Gid      int
	Name     string
	Sort     int
	Router   string `orm:"unique"`
	Describe string
}

//管理系统功能分组
type AdminSysFuncGroup struct {
	Id       int
	Created  time.Time `orm:"auto_now_add;type(datetime)"`
	Updated  time.Time `orm:"auto_now;type(datetime)"`
	Pid      int
	Name     string
	Sort     int
	Describe string
}

//管理员拥有的分组
type AdminInGroup struct {
	Id  int
	Aid int `orm:"index"`
	Gid int
}

//管理员权限
type AdminPower struct {
	Id       int
	AdminId  int
	AccessId int
	Power    int
}

func (t *AdminPower) TableUnique() [][]string {
	return [][]string{
		{"AdminId", "AccessId"},
	}
}

// 地区
type Region struct {
	Id        int
	Name      string `orm:"size(50);index"`
	Pid       int
	ShortName string `orm:"size(50)"`
	Level     int8
	CityCode  string  `orm:"size(20)"`
	ZipCode   string  `orm:"size(20)"`
	MergeName string  `orm:"index"`
	Longitude float64 `orm:"digits(8);decimals(5)"`
	Latitude  float64 `orm:"digits(8);decimals(5)"`
	English   string
}
